package jiejie.qiye;

import java.util.Arrays;
import java.util.Scanner;

public class baidu1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();//纪念品件数
        int m=sc.nextInt();//重量
        int k=sc.nextInt();//预算
        int[][] nums = new int[n][3];

        for(int i=0; i<n; i++){
            sc.nextLine();
            for(int j=0; j<3; j++){
                nums[i][j]=sc.nextInt();
            }
        }
        getRes(m,k,nums);

    }
    public static void getRes(int m, int k, int[][] nums){
        int weight=0;
        int money=0;
        int count=0;
        while(weight<=m && money<=k){
            int tmp=getMax(nums);
            weight=weight+nums[tmp][1];
            if(weight>m)
                break;
            money=money+nums[tmp][0];
            if(money>k)
                break;
            count++;
            nums[tmp][2]=0;
        }
        System.out.println(count);
    }
    public static int getMax(int[][] nums){
        int max=nums[0][2];
        int flag=0;
        for(int i=1;i<nums.length; i++){
            if(nums[i][2]>max){
                max=nums[i][2];
                flag=i;
            }
            if(nums[i][2]==max){
                if(nums[i][0]<nums[flag][0]){
                    flag=i;
                }
                if(nums[i][0]==nums[flag][0]){
                    if(nums[i][1]<nums[flag][1])
                        flag=i;
                }
            }
        }
        return flag;
    }
}
